package com.aaa.ssm.controller;


import com.aaa.ssm.entity.SysRole;
import com.aaa.ssm.service.impl.SysRoleServiceImpl;
import com.aaa.ssm.util.Page;
import com.aaa.ssm.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("role")
public class SysRoleController extends BaseController{
    @Resource
    private SysRoleServiceImpl sysRoleService;
    @PostMapping("queryByPage")
    @ResponseBody
    public Result queryByPage(@RequestBody Page<SysRole> page){
        return success(sysRoleService.queryByPage(page));
    }
    @GetMapping("queryByParam")
    public Result queryByParam(@RequestBody SysRole sysRole){
        List<SysRole> patientList=sysRoleService.queryByParam(sysRole);
        return success(patientList);
    }

    @GetMapping("queryById")
    public Result queryById(Integer userId){
        return success(sysRoleService.queryById(userId));
    }
    @PutMapping("add")
    private Result add(@RequestBody SysRole sysRole){
        return success(sysRoleService.add(sysRole));
    }
    @PutMapping("update")
//    @ResponseBody
    private Result update(@RequestBody SysRole sysRole){
        return success(sysRoleService.update(sysRole));
    }

    @DeleteMapping("delete")
//    @ResponseBody
    private Result delete(int roleId){

        return  success(sysRoleService.delete(roleId));
    }

    /**
     * 添加角色权限
     * @param roleId
     * @param menuIds
     * @return
     */
    @GetMapping("addRoleAndMenu")
    private Result addRoleAndMenu(Integer roleId,String menuIds){
        return success(sysRoleService.addRoleAndMenu(roleId,menuIds));
    }

    /**
     * 根据角色查询权限编号
     * @param roleId
     * @return
     */
    @GetMapping("queryMenuIdsByRoleId")
    public Result queryMenuIdsByRoleId(Integer roleId){
        return success(sysRoleService.queryMenuIdsByRoleId(roleId));
    }

}
